<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/** @var \Magento\Customer\Block\Form\Edit $this */
?>
<form class="form form-edit-account" action="<?php echo $this->getUrl('customer/account/editPost') ?>" method="post" id="form-validate" enctype="multipart/form-data" data-hasrequired="<?php echo __('* Required Fields') ?>" autocomplete="off">
    <fieldset class="fieldset info">
        <?php echo $this->getBlockHtml('formkey')?>
        <legend class="legend"><span><?php echo __('Account Information') ?></span></legend><br>
        <?php echo $this->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')->setObject($this->getCustomer())->toHtml() ?>
        <div class="field email required">
            <label class="label" for="email"><span><?php echo __('Email Address') ?></span></label>
            <div class="control">
                <input type="email" name="email" id="email" value="<?php echo $this->escapeHtml($this->getCustomer()->getEmail()) ?>" title="<?php echo __('Email Address') ?>" class="input-text" data-validate="{required:true, 'validate-email':true}">
            </div>
        </div>
        <?php $_dob = $this->getLayout()->createBlock('Magento\Customer\Block\Widget\Dob') ?>
        <?php $_taxvat = $this->getLayout()->createBlock('Magento\Customer\Block\Widget\Taxvat') ?>
        <?php $_gender = $this->getLayout()->createBlock('Magento\Customer\Block\Widget\Gender') ?>
        <?php if ($_dob->isEnabled()): ?>
            <?php echo $_dob->setDate($this->getCustomer()->getDob())->toHtml() ?>
        <?php endif ?>
        <?php if ($_taxvat->isEnabled()): ?>
            <?php echo $_taxvat->setTaxvat($this->getCustomer()->getTaxvat())->toHtml() ?>
        <?php endif ?>
        <?php if ($_gender->isEnabled()): ?>
            <?php echo $_gender->setGender($this->getCustomer()->getGender())->toHtml() ?>
        <?php endif ?>
        <div class="field choice">
            <input type="checkbox" name="change_password" id="change-password" value="1" title="<?php echo __('Change Password') ?>"<?php if($this->getChangePassword()): ?> checked="checked"<?php endif; ?> class="checkbox"/>
            <label class="label" for="change-password"><span><?php echo __('Change Password') ?></span></label>
        </div>
    </fieldset>

    <fieldset class="fieldset password">
        <legend class="legend"><span><?php echo __('Change Password') ?></span></legend><br>
        <div class="field password current required">
            <label class="label" for="current-password"><span><?php echo __('Current Password') ?></span></label>
            <div class="control">
                <input type="password" class="input-text" name="current_password" id="current-password">
            </div>
        </div>
        <div class="field new password required">
            <label class="label" for="password"><span><?php echo __('New Password') ?></span></label>
            <div class="control">
                <input type="password" class="input-text" name="password" id="password">
            </div>
        </div>
        <div class="field confirm password required">
            <label class="label" for="confirmation"><span><?php echo __('Confirm New Password') ?></span></label>
            <div class="control">
                <input type="password" class="input-text" name="confirmation" id="confirmation">
            </div>
        </div>
    </fieldset>
    <div class="actions-toolbar">
        <div class="primary">
            <button type="submit" class="action save primary" title="<?php echo __('Save') ?>"><span><?php echo __('Save') ?></span></button>
        </div>
        <div class="secondary">
            <a class="action back" href="<?php echo $this->escapeUrl($this->getBackUrl()) ?>"><span><?php echo __('Go back') ?></span></a>
        </div>
    </div>
</form>
<script type="text/javascript">
    require([
        "jquery",
        "mage/mage"
    ], function($){

        $('#change-password').mage('setPassword', {
            'currentPasswordId': '#current-password',
            'passwordId': '#password',
            'confirmationId': '#confirmation',
            'passwordContainer': 'fieldset.fieldset.password',
            'showOnDefault': <?php echo $this->getChangePassword() ? 'true' : 'false' ?>
        });

        var dataForm = $('#form-validate');
        var ignore = <?php echo $_dob->isEnabled() ? '\'input[id$="full"]\'' : 'null'; ?>;
        dataForm.mage('validation', {
        <?php if ($_dob->isEnabled()): ?>
            errorPlacement: function(error, element) {
                if (element.prop('id').search('full') !== -1) {
                    var dobElement = $(element).parents('.customer-dob'),
                        errorClass = error.prop('class');
                    error.insertAfter(element.parent());
                    dobElement.find('.validate-custom').addClass(errorClass)
                        .after('<div class="' + errorClass + '"></div>');
                }
                else {
                    error.insertAfter(element);
                }
            },
            ignore: ':hidden:not(' + ignore + ')'
        <?php else: ?>
            ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
        <?php endif ?>
        });

    });
</script>
